package com.roy.reversi.view;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import com.roy.reversi.controller.Controller;
import com.roy.reversi.model.Chessboard;

public class ControlPanel extends JPanel {

	private static final long serialVersionUID = 1L;
	private Controller controller;
	private JLabel jlCurPlayer;
	private JLabel jlWhiteNum;
	private JLabel jlBlackNum;
	private JButton jbNewGame;
	
	public ControlPanel(Controller controller) {
		this.controller = controller;
		initialize();
	}

	private void initialize() {
		this.setSize(80, Chessboard.TOTAL_HEIGHT);
		this.setLayout(null);
		this.setBackground(Color.WHITE);
		this.setOpaque(false);
		
		JLabel jl1, jl2, jl3;
		
		jl1 = new JLabel("当前玩家");
		jl1.setBounds(5, 5, 55, 25);
		
		jlCurPlayer = new JLabel();
		jlCurPlayer.setBounds(5, 30, 55, 25);
		jlCurPlayer.setForeground(Color.red);
		
		jl2 = new JLabel("黑子数");
		jl2.setBounds(5, 75, 55, 25);
		
		jlBlackNum = new JLabel();
		jlBlackNum.setBounds(5, 100, 55, 25);
		jlBlackNum.setForeground(Color.red);
		
		jl3 = new JLabel("白子数");
		jl3.setBounds(5, 140, 55, 25);
		
		jlWhiteNum = new JLabel();
		jlWhiteNum.setBounds(5, 165, 55, 25);
		jlWhiteNum.setForeground(Color.red);
		
		jbNewGame = new JButton("开始");
		jbNewGame.setBounds(5, 295, 60, 25);
		jbNewGame.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				controller.newGame();
			}
		});
		
		this.add(jl1);
		this.add(jl2);
		this.add(jl3);
		this.add(jlCurPlayer);
		this.add(jlBlackNum);
		this.add(jlWhiteNum);
		this.add(jbNewGame);
		
		setInfo();
	}
	
	public void setInfo(){
		jlCurPlayer.setText(controller.getCurPlayer());
		jlBlackNum.setText(controller.getBlackNum() + "");
		jlWhiteNum.setText(controller.getWhiteNum() + "");
	}

}
